package com.sudo.api.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@EnableOpenApi
public class Swagger2 {

    /**
     *配置Swagger2核心 docket
     * 原路径：https://localhost:8088/swagger-ui.html
     * bootstrap:https://localhost:8088/doc.html
     *
     * 使用方法：
     * @ ApiIgnore ：给controller加上该注解，表示忽略该controller的api文档
     * @ Api(value = "接口说明",tags = {"详细信息"}) ：  给controller加上该注解
     * @ ApiOperation(value="接口名称",notes="接口补充说明", httpMethod = "GET/POST")：给方法上加上该注解，表示针对某一个接口解释
     * @ ApiModel(value="对象BO",description="传参BO说明")：给BO加上该注解
     * @ ApiModelProperty(value ="属性名"，name="参数",example="参数例子",required=true：是否必须) ：给BO的属性加该注解
     *
     */
    @Bean
    public Docket createDocket() {
        //指定api类型为swagger2
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())
                .select().apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
                //所有controller
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("JBuss 系统api文档")
                .contact(new Contact("为道日损", "https://www.sudo.ren", "fxw7468@qq.com"))
                .description("为开发者提供详细的JBuss接口文档").version("2.0")
                //网站地址
                .termsOfServiceUrl("https://www.sudo.ren")
                .build();
    }
}
